<?php
//ADD THE POSTED DATA TO THE DATABASE UNDER THE CURRENT SESSION USER ID
$fcomid = "";
$famount = "";
$ffor = "";
$fdate = "";
$fdepwith = "";
$fcomments = "";
$errorMessage = "";
$num_rows = 0;
$notification = "";
$fmemid = "";

function quote_smart($value, $handle) {

   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }

   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value, $handle) . "'";
   }
   return $value;
}

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

	//====================================================================

	//====================================================================
	$fcomid = $_SESSION['comid'];
	$fmemid = $_SESSION['memid'];
	$famount = $_POST['total'];
$htmldate = date('Y-m-d');
$fdate = strtotime($htmldate);
$fdepwith  = "recon";

	$fcomid = htmlspecialchars($fcomid);
	$famount = htmlspecialchars($famount);

	//====================================================================
	//	Write to the database
	//====================================================================
	if ($errorMessage == "") {

require 'config.php';

	$db_handle = mysql_connect($server, $user_name, $pass_word);
	$db_found = mysql_select_db($database, $db_handle);

	if ($db_found) {
		
		$balquery = "SELECT * FROM  `Company` WHERE id = $fcomid";
	$balsult = mysql_query($balquery) or die(mysql_error());
	$balrow = mysql_fetch_array($balsult);
	$curbal = $balrow['curbal'];
	$comname = $balrow['name'];

$fcomid = quote_smart($fcomid, $db_handle);
$famount = quote_smart($famount, $db_handle);

	//====================================================================

  
			$sqlwe = "INSERT INTO pettyapp_log (id, comid, amount, dfor, tdate, pinout, memid) VALUES (NULL, $fcomid, '$famount',\"Recon, Outstanding: \", $fdate, \"$fdepwith\", $fmemid);";
			$resultwe = mysql_query($sqlwe);
			
			if($resultwe){
			$notification = "<h4 align=\"center\" style=\"color:#0C0\">Recon Log has been captured</h4>";}
			else
			{$notification = "<h4 align=\"center\" style=\"color:#F00\">Recon Log has not been captured</h4>";
				}

			mysql_close($db_handle);


		}
else
{
$errorMessage = "<h4 align=\"center\" style=\"color:#0C0\">Database not found</h4>";
}
	}
	else {
		$errorMessage = "<h4 align=\"center\" style=\"color:#0C0\">An error occurred</h4>";
	}




	}




?>